﻿<%@ WebHandler Language="C#" Class="Upload" %>

using System;
using System.IO;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Net;
using System.Configuration;
using System.Collections;
using ReportBusiness;

/*
 * Description:MES文件上传
 * Copyright (c) : 通力凯顿（北京）系统集成有限公司
 * Writer:zhunan
 * create Date:2023.5.11
 */

public class Upload : IHttpHandler
{
    public bool IsReusable { get { return false; } }
    private uMESReportOracleDAL dal = new uMESReportOracleDAL();
    public void ProcessRequest(HttpContext context)
    {
        if (context.Request.QueryString["action"].ToString() == "upload")
        {
            context.Response.ContentType = "application/json";
            string root = HttpContext.Current.Request.PhysicalApplicationPath;
            try
            {
                HttpFileCollection Files = HttpContext.Current.Request.Files;// 多个文件
                foreach (string strFile in Files)
                {
                    HttpPostedFile uploadFile = Files[strFile];
                    uploadFile.SaveAs(context.Server.MapPath("../../Files/" + uploadFile.FileName));//保存文件
                    context.Response.Write(JsonConvert.SerializeObject(new { status = 200, msg = Files[strFile].FileName + " 保存成功" }));
                }
            }
            catch (Exception e)
            {
                context.Response.Write(JsonConvert.SerializeObject(new { status = 500, msg = e.Message }));
            }
        }
    }
}